home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 February: Tool Chest / Apple Developer CD Series Tool Chest February 1996 (Apple Computer)(1996).iso / Sample Code / Sample Code Update 01⁄96 / Fragment Tool / Sources / Initialize.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-11-20  |  4.0 KB  |  187 lines  |  [TEXT/MPCC]

  1. /*
  2.     File:        Initialize.c
  3.     
  4.     Contains:    Initialization code for this application
  5.     
  6.     Written by:    Chris White, Developer Technical Support
  7.     
  8.     Copyright:    © 1995 by Apple Computer, Inc., all rights reserved.
  9.     
  10.     Change History (most recent first):
  11.     
  12.                   9/28/95    CW        First release
  13.  
  14. */
  15.  
  16.  
  17. #ifndef __DIALOGS__
  18.     #include <Dialogs.h>
  19. #endif
  20.  
  21. #ifndef __FONTS__
  22.     #include <Fonts.h>
  23. #endif
  24.  
  25. #ifndef __WINDOWS__
  26.     #include <Windows.h>
  27. #endif
  28.  
  29. #ifndef __MENUS__
  30.     #include <Menus.h>
  31. #endif
  32.  
  33. #ifndef __TEXTEDIT__
  34.     #include <TextEdit.h>
  35. #endif
  36.  
  37. #ifndef __EVENTS__
  38.     #include <Events.h>
  39. #endif
  40.  
  41. #ifndef __OSEVENTS__
  42.     #include <OSEvents.h>
  43. #endif
  44.  
  45. #ifndef __GESTALTEQU__
  46.     #include <GestaltEqu.h>
  47. #endif
  48.  
  49. #ifndef __SEGLOAD__
  50.     #include <SegLoad.h>
  51. #endif
  52.  
  53. #ifndef __DRAG__
  54.     #include <Drag.h>
  55. #endif
  56.  
  57. #ifndef __CODEFRAGMENTS__
  58.     #include <CodeFragments.h>
  59. #endif
  60.  
  61.  
  62.  
  63. #ifndef __FRAGMENTTOOL__
  64.     #include "FragmentTool.h"
  65. #endif
  66.  
  67. #ifndef __MENUSTUFF__
  68.     #include "MenuStuff.h"
  69. #endif
  70.  
  71. #ifndef __UTILITIES__
  72.     #include "Utilities.h"
  73. #endif
  74.  
  75. #ifndef __PROTOTYPES__
  76.     #include "Prototypes.h"
  77. #endif
  78.  
  79.  
  80.  
  81.  
  82. const int32 kSleepTime = 60L;
  83.  
  84.  
  85. void InitToolbox ( void )
  86. {    
  87.     InitGraf ( &qd.thePort );
  88.     InitFonts ( );
  89.     InitWindows ( );
  90.     InitMenus ( );
  91.     TEInit ( );
  92.     InitDialogs ( nil );
  93.     InitCursor ( );
  94.     
  95.     FlushEvents ( everyEvent, 0 );
  96.     
  97.     return;
  98. }
  99.  
  100.  
  101.  
  102. void InitApplication ( void )
  103. {
  104.     SetMenuBar ( GetNewMBar ( kMenuBarID ) );
  105.     AddResMenu ( GetMHandle ( kAppleMenu ), 'DRVR' );
  106.     DrawMenuBar ( );
  107.     
  108.     if ( !CheckConfiguration ( ) )
  109.     {
  110.         AlertUser ( kNeedSystem7, 0, nil );
  111.         ExitToShell ( );
  112.     }
  113.     
  114.     gQuit = false;                          // Initialize flag that controls main event loop
  115.     
  116.     // We need to get null events often enough to blink the caret correctly
  117.     gSleepTime = (GetCaretTime ( ) < kSleepTime) ? GetCaretTime ( ) : kSleepTime;
  118.     
  119.     
  120.     InitListClickLoop ( );                // Creates the UPPs (etc) for the ClickLoop
  121.     InitDragHandlers ( );                // Creates the UPPs for the Drag Handlers
  122.     InstallAppleEventHandlers ( );        // Installs the AE handlers for the required AE
  123.     
  124.     AdjustMenus ( );
  125.     
  126.     // Create any other RoutineDescriptors we may need
  127.     gOutlineUserItemUPP = NewUserItemProc ( OutlineUserItem );
  128.     
  129.     return;
  130. }
  131.  
  132.  
  133.  
  134.  
  135.  
  136. //
  137. // We'll limit the scope of some of our function to the current source file
  138. // by  declairing them static. Although this has limited advantages as
  139. // far as encapsulation is concerned, it can make the source code a little
  140. // more readable.
  141. //
  142. static Boolean CheckConfiguration ( void )
  143. {
  144.     long        theResult;
  145.     OSErr        theErr;
  146.     Boolean        bHasAppleEvents, bHasFSpTraps, bHasFSpStdFile, bHasCodeFragmentManager;
  147.     
  148.     
  149.     // Verify that we can run on the current configuration
  150.     
  151.     // We require AppleEvent Manager and FSSpec-based file traps and Standard File
  152.     theErr = Gestalt ( gestaltAppleEventsAttr, &theResult );
  153.     bHasAppleEvents = (theErr == noErr && (theResult & (1L << gestaltAppleEventsPresent)));
  154.     
  155.     theErr = Gestalt ( gestaltFSAttr, &theResult );
  156.     bHasFSpTraps = (theErr == noErr && (theResult & (1L << gestaltHasFSSpecCalls)));
  157.     
  158.     theErr = Gestalt ( gestaltStandardFileAttr, &theResult );
  159.     bHasFSpStdFile = (theErr == noErr && (theResult & (1L << gestaltStandardFile58)));
  160.     
  161.     // Ensure CFM or CFM-68K is available
  162.     theErr = Gestalt ( gestaltCFMAttr, &theResult );
  163.     bHasCodeFragmentManager = (theErr == noErr && (theResult & (1L << gestaltCFMPresent)));
  164.  
  165.     // We would also like the Drag Manager
  166.     theErr = Gestalt ( gestaltDragMgrAttr, &theResult );
  167.     gHasDragManager = (theErr == noErr && (theResult & (1L << gestaltDragMgrPresent)));
  168.  
  169.  
  170.     // It isn't enough to use Gestalt because we may not have sucessfully linked
  171.     // to the DragLib shared library. So, we also need to test one of the symbols
  172.     // against kUnresolvedSymbol to make sure we have a valid connection to it.
  173.     // Things like memory limitations to someone having the thing open with
  174.     // write permission could cause it to fail.
  175.     
  176. #if GENERATINGCFM
  177.     if ( gHasDragManager )
  178.         gHasDragManager = (InstallTrackingHandler != (void*) kUnresolvedSymbolAddress);
  179. #endif
  180.     
  181.     return (bHasAppleEvents & bHasFSpTraps & bHasFSpStdFile & bHasCodeFragmentManager);
  182. }
  183.  
  184.  
  185.  
  186.  
  187.